using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;

namespace Helpers
{
    public static class CryptoHelper
    {
        /// <summary>
        /// Creates and MD5 hash of a string. Useful for hashing passwords.
        /// </summary>
        /// <param name="plainText"></param>
        /// <returns></returns>
        public static string SHA512(string plainText)
        {
            // converting the string to a byte array
            ASCIIEncoding encoder = new ASCIIEncoding();
            byte[] plainBytes = encoder.GetBytes(plainText);

            // feeding the byte array to the MD5 hasher
            //SHA512Managed Sha = new SHA512Managed();
            MD5CryptoServiceProvider Sha = new MD5CryptoServiceProvider();
            byte[] hashedBytes = Sha.ComputeHash(plainBytes);

            // converting the hash back to a string
            string hash = BitConverter.ToString(hashedBytes).ToLower().Replace("-", "");

            return hash;
        }
    }
}